import java.nio.FloatBuffer;
import com.sun.opengl.util.*;

class PaddleSystem {

  final static int maxPaddles = 1;
  int curIndex;

  Paddle[] paddles;

  PaddleSystem() {
    paddles = new Paddle[maxPaddles];
    for(int i=0; i<maxPaddles; i++) paddles[i] = new Paddle();
    curIndex = 0;
  }

  void fadeToColor(GL gl, float r, float g, float b, float speed) {
    gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
    gl.glColor4f(r, g, b, speed);
    gl.glBegin(GL.GL_QUADS);
    gl.glVertex2f(0, 0);
    gl.glVertex2f(width, 0);
    gl.glVertex2f(width, height*.95);
    gl.glVertex2f(0, height*.95);
    gl.glEnd();
  }

  void updateAndDraw(){
    PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;         // processings opengl graphics object
    GL gl = pgl.beginGL();
    gl.glEnable(GL.GL_BLEND);
    fadeToColor(gl,0,0,0,0.05);
    gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE);
    gl.glEnable(GL.GL_LINE_SMOOTH);
    gl.glLineWidth(1);
    gl.glBegin(GL.GL_QUADS);
    for(int i=0; i<maxPaddles; i++) {
      if(paddles[i].alpha > 0) {
        paddles[i].update();
        paddles[i].drawOldSchool(gl);
      }
    }
    gl.glEnd();
    gl.glDisable(GL.GL_BLEND);
    pgl.endGL();
  }

  void addPaddle() {
    paddles[curIndex].init(mouseX);
    curIndex++;
    if(curIndex >= maxPaddles) curIndex = 0;
  }
}

